<template>
  <div class="app-container">
    医院设置添加
    <el-form label-width="120px">
      <el-form-item label="医院名称">
        <el-input v-model="hospitalSet.hosname"/>
      </el-form-item>
      <el-form-item label="医院编号">
        <el-input v-model="hospitalSet.hoscode"/>
      </el-form-item>
      <el-form-item label="api基础路径">
        <el-input v-model="hospitalSet.apiUrl"/>
      </el-form-item>
      <el-form-item label="联系人姓名">
        <el-input v-model="hospitalSet.contactsName"/>
      </el-form-item>
      <el-form-item label="联系人手机">
        <el-input v-model="hospitalSet.contactsPhone"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="saveOrUpdate">
          {{ isUpdate ? '修改' : '新增' }}
        </el-button>
      </el-form-item>
    </el-form>
  </div>

</template>

<script>
import {saveHospSetApi, updateHospSetApi} from "../../api/hospSet";

export default {
  name: "add",
  props: ['info'],
  data() {
    return {
      hospitalSet: {},
      isUpdate: false
    }
  },
  methods: {
    saveOrUpdate() {
      if (this.isUpdate) {
        //修改
        updateHospSetApi(this.hospitalSet)
        this.$message.success('修改成功！')
      } else {
        //新增
        saveHospSetApi(this.hospitalSet)
        this.$message.success('添加成功！')
      }
      //页面跳转至列表
      this.$router.push({name: 'HospSetList'})
    }
  },
  mounted() {
    console.log(123)
    //页面初始化
    this.hospitalSet = {}

    if (this.info instanceof Object) {
      //修改
      this.hospitalSet = this.info
      this.isUpdate = true
    }
  },
}
</script>

<style scoped>

</style>
